package cn.langpy.dblistener.core.model.transform;

import cn.langpy.dblistener.core.model.OperateType;

import java.util.ArrayList;
import java.util.List;

/**
 * 事件行
 * zhangchang
 */
public class EventRow implements Cloneable{
    /**
     * @see OperateType
     */
    private OperateType operate;
    private String database;
    private String table;
    private String sql;
    private Boolean ddl = false;
    private List<EventColumn> befores;
    private List<EventColumn> afters;

    public OperateType getOperate() {
        return operate;
    }

    public void setOperate(OperateType operate) {
        this.operate = operate;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public Boolean getDdl() {
        return ddl;
    }

    public void setDdl(Boolean ddl) {
        this.ddl = ddl;
    }

    public List<EventColumn> getBefores() {
        return befores;
    }

    public void setBefores(List<EventColumn> befores) {
        this.befores = befores;
    }

    public List<EventColumn> getAfters() {
        return afters;
    }

    public void setAfters(List<EventColumn> afters) {
        this.afters = afters;
    }
    @Override
    public EventRow clone() throws CloneNotSupportedException {
        return (EventRow)super.clone();
    }
    @Override
    public String toString() {
        return "EventRow{" +
                "operate=" + operate +
                ", database='" + database + '\'' +
                ", table='" + table + '\'' +
                ", sql='" + sql + '\'' +
                ", ddl=" + ddl +
                ", befores=" + befores +
                ", afters=" + afters +
                '}';
    }

    public static EventRow.Builder builder() {
        return new EventRow.Builder();
    }
    public static class Builder {
        private OperateType operate;
        private String database;
        private String table;
        private String sql;
        private Boolean ddl;
        private List<EventColumn> befores;
        private List<EventColumn> afters;

        public Builder operate(OperateType operate) {
            this.operate = operate;
            return this;
        }
        public Builder database(String database) {
            this.database = database;
            return this;
        }
        public Builder table(String table) {
            this.table = table;
            return this;
        }
        public Builder sql(String sql) {
            this.sql = sql;
            return this;
        }
        public Builder ddl(Boolean ddl) {
            this.ddl = ddl;
            return this;
        }
        public Builder befores(List<EventColumn> befores) {
            this.befores = befores;
            return this;
        }
        public Builder afters(List<EventColumn> afters) {
            this.afters = afters;
            return this;
        }
        public EventRow build() {
            EventRow eventRow = new EventRow();
            eventRow.setOperate(operate);
            eventRow.setDatabase(database);
            eventRow.setTable(table);
            eventRow.setSql(sql);
            eventRow.setDdl(ddl);
            eventRow.setBefores(befores);
            eventRow.setAfters(afters);
            return eventRow;
        }
    }
}
